<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h2{
            text-align: center;
        }
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border-top: 1px solid #ddd;
            border-bottom: 1px solid #ddd;
            padding: 8px;
            text-align: center;
        }
        thead tr{
            background-color: cyan;
        }
    </style>
</head>
<body>
    <h2>商品信息表</h2>
    <table id="shangpingTable">
        <thead>
            <tr>
                <th>编号</th>
                <th>商品名称</th>
                <th>单价</th>
                <th>数量</th>
                <th>小计</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>01</td>
                <td>牛仔外套</td>
                <td>99元</td>
                <td>1件</td>
                <td>99元</td>
            </tr>
            <tr>
                <td>02</td>
                <td>帽子</td>
                <td>25元</td>
                <td>2件</td>
                <td>50元</td>
            </tr>
            <tr>
                <td>03</td>
                <td>双肩包</td>
                <td>100元</td>
                <td>1件</td>
                <td>100元</td>
            </tr>
        </tbody>
    </table>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            let tableBody = document.querySelector('#shangpingTable tbody');
            let rows = tableBody.querySelectorAll('tr');
     
            for (let i = 0; i < rows.length; i++) {
                rows[i].addEventListener('mouseover', function() {
                    this.style.backgroundColor = 'gray';
                },false);
     
                rows[i].addEventListener('mouseout', function() {
                    this.style.backgroundColor = '';
                },false);
            }
        });
    </script>
</body>
</html>